﻿using BCDto.TMS.DisableArea;
using BCDto.TMS.DisableArea.DisableAreaBaseDto;
using BCService.TMS.DisableArea;
using BCTMSRESTful.Configs;
using BCTMSRESTful.Controllers.Management;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;

namespace BCTMSRESTful.Controllers.Management.DisableArea
{

    [ApiExplorerSettings(GroupName = "TMSAdmin")]
    [Route("api/v1/sim/[controller]")]
    public class DisableAreaController : ManagementBaseController
    {
        private readonly IDisableAreaService disableAreaService;

        public DisableAreaController(IDisableAreaService disableAreaService)
        {
            this.disableAreaService = disableAreaService;
        }
        /// <summary>
        /// 获取禁卸货区域
        /// </summary>
        /// <param name="provinceCode">省份编码</param>
        /// <param name="cityCode">城市编码</param>
        /// <response code="200">获取禁卸货区域</response>
        /// <returns></returns>
        [Log("获取禁卸货区域")]
        [HttpGet("{province_code}/{city_code}")]
        [ProducesResponseType(typeof(IEnumerable<DisableAreaDto>), 200)]
        public IActionResult Get([FromRoute(Name = "province_code")] string provinceCode, [FromRoute(Name = "city_code")] string cityCode)
        {
            return this.Ok(this.disableAreaService.GetDisableAreaInfo(provinceCode, cityCode));
        }
        /// <summary>
        /// 查询禁卸货区域坐标
        /// </summary>
        /// <param name="disableAreaId">禁止装卸货区域ID</param>
        /// <response code="200">查询禁卸货区域坐标</response>
        /// <returns></returns>
        [Log("查询禁卸货区域坐标")]
        [HttpGet("[action]/{disable_area_id}")]
        [ProducesResponseType(typeof(IEnumerable<DisableAreaDto>), 200)]
        public IActionResult Query([FromRoute(Name = "disable_area_id")] long disableAreaId)
        {
            return this.Ok(this.disableAreaService.QueryDisableAreaRangeCoordinate(disableAreaId));
        }
        /// <summary>
        /// 查询禁卸货区域车辆类型
        /// </summary>
        /// <param name="disableAreaId">禁止装卸货区域ID</param>
        /// <response code="200">查询禁卸货区域车辆类型</response>
        /// <returns></returns>
        [Log("查询禁卸货区域车辆类型")]
        [HttpGet("[action]/{disable_area_id}")]
        [ProducesResponseType(typeof(IEnumerable<DisableAreaDto>), 200)]
        public IActionResult QueryDisableAreaVehicleTypeReference([FromRoute(Name = "disable_area_id")] long disableAreaId)
        {
            return this.Ok(this.disableAreaService.QueryDisableAreaVehicleTypeReference(disableAreaId));
        }
        /// <summary>
        /// 新增禁卸货区域
        /// </summary>
        /// <param name="disableareabase">禁止装卸货区域请求对象</param>
        /// <response code="201">新增禁卸货区域</response>
        /// <returns></returns>
        [Log("新增禁卸货区域")]
        [HttpPost]
        [ProducesResponseType(typeof(DisableAreaDto), 201)]
        public IActionResult Post([FromBody] DisableAreaBaseDto disableareabase)
        {
            var result = disableAreaService.AddDisableArea(this.Admin, disableareabase.DisableArea, disableareabase.RangeCoordinateList, disableareabase.VehicleTypeReferenceList);
            return this.Created(string.Format("/api/v1/TMS/DisableArea/{0}", result.DisableAreaId), result);
        }
        /// <summary>
        /// 修改禁卸货区域
        /// </summary>
        /// <param name="disableareabase">禁止装卸货区域请求对象</param>
        /// <param name="disableAreaId">禁卸货区域ID</param>
        /// <response code="200">修改后的禁卸货区域</response>
        /// <response code="401">请求需要认证或者认证信息已过期。</response>
        /// <returns></returns>
        [Log("修改禁卸货区域")]
        [HttpPut("{disable_area_id}")]
        [ProducesResponseType(typeof(DisableAreaDto), 200)]
        public IActionResult PutDisableArea([FromBody] DisableAreaBaseDto disableareabase, [FromRoute(Name = "disable_area_id")] long disableAreaId)
        {
            return this.Ok(this.disableAreaService.UpdateDisableArea(this.Admin, disableareabase.DisableArea, disableareabase.RangeCoordinateList, disableareabase.VehicleTypeReferenceList, disableAreaId));
        }
        /// <summary>
        /// 删除禁卸货区域
        /// </summary>
        /// <param name="disableAreaId">禁止装卸货区域ID</param>
        /// <response code="204">删除成功</response>
        /// <returns></returns>
        [Log("删除禁卸货区域")]
        [HttpDelete("{disable_area_id}")]
        [ProducesResponseType(typeof(bool), 200)]
        public IActionResult DeleteDisableArea([FromRoute(Name = "disable_area_id")] long disableAreaId)
        {
            return this.Ok(this.disableAreaService.DeleteDisableArea(disableAreaId));
        }
    }
}
